﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NetSysData;
namespace BladeTecWebApplication.Admin
{
    public partial class EditCategory : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                NetSysData.NetSysData data = new NetSysData.NetSysData();
                pnlConfirmationForm.Visible = false;
                int cat_id;
                QUESTION_CATEGORY cat;
                try
                {
                    cat_id = Int32.Parse(Request.QueryString["category_id"]);
                }
                catch (Exception)
                {
                    // show error
                    return;
                }

                if (Request.QueryString["category_id"] != "")
                {
                    cat = data.GetCategory(cat_id);
                    if (cat == null)
                    {
                        // show error
                        return;
                    }
                }
                else
                {
                    // show error
                    return;
                }


                txtCategoryName.Text = cat.CATEGORY_NAME;
                hflblCatID.Value = cat_id.ToString();
            }
        }

        protected void btnAddCategory_Click(object sender, EventArgs e)
        {
            NetSysData.NetSysData data = new NetSysData.NetSysData();

            QUESTION_CATEGORY qc = data.GetCategory(Int32.Parse(hflblCatID.Value));
            qc.CATEGORY_NAME = txtCategoryName.Text;

            data.Save();

            txtCategoryName.Text = qc.CATEGORY_NAME;

            //lblCategoryConfirm.Text = txtCategoryName.Text;

            pnlQuestionCategory.Visible = false;
            pnlConfirmationForm.Visible = true;
        }
    }
}